package site.zhangzhuo.learn_springboot.listener;

import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Component;

@Component
public class CustomEventPublisher {
    private final ApplicationEventPublisher publisher;

    public CustomEventPublisher(ApplicationEventPublisher publisher) {
        this.publisher = publisher;
    }

    public void doSomethingAndPublishAnEvent(final String message) {
        System.out.println("Publishing custom event.");
        CustomApplicationEvent customApplicationEvent = new CustomApplicationEvent(this, message);
        publisher.publishEvent(customApplicationEvent);
    }
}
